package com.example.LayoutGrid;

import java.io.IOException;

import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;

public class MyGestureDetectorListener extends GestureDetector.SimpleOnGestureListener {
	private ScreenControl screenControl;
	
	public MyGestureDetectorListener(ScreenControl screenControl)
	{
		super();
		this.screenControl=screenControl;
	}
	
    @Override
    public boolean onSingleTapUp(MotionEvent ev) {
    	//Toast.makeText(screenControl.getContext(), "onSingleTapUp", Toast.LENGTH_SHORT).show();
    	try {
			screenControl.sendLeftClick(screenControl.posX+(int)ev.getX(), screenControl.posY+(int)ev.getY());
		} catch (IOException e) {
			 //TODO Auto-generated catch block
			e.printStackTrace();
		}
        Log.d("DEBUG","onSingleTapUp");
        return true;
    }

    @Override
    public void onShowPress(MotionEvent ev) {
        //Log.d("DEBUG","onShowPress");
    }

    @Override
    public void onLongPress(MotionEvent ev) {
    	try {
			screenControl.sendRightClick(screenControl.posX+(int)ev.getX(),screenControl.posY+(int)ev.getY());
		} catch (IOException e) {
			 //TODO Auto-generated catch block
			e.printStackTrace();
		}
        Log.d("DEBUG","onLongPress12");
    }

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2,
            float distanceX, float distanceY) {
        Log.d("DEBUG","onScroll");
        return true;
    }

    @Override
    public boolean onDown(MotionEvent ev) {
        Log.d("DEBUG","onDownd");
        return true;
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
    	
    	screenControl.posX+=(int)(e1.getX()-e2.getX());
    	screenControl.posY+=(int)(e1.getY()-e2.getY());
    	try {
			screenControl.setImage();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
        Log.d("DEBUG","onFling");
        return true;
    }
    @Override
	public boolean onDoubleTap(MotionEvent event){
    	try {
			screenControl.sendLeftClick(screenControl.posX+(int)event.getX(), screenControl.posY+(int)event.getY());
		} catch (IOException e) {
			 //TODO Auto-generated catch block
			e.printStackTrace();
		}
        Log.d("DEBUG","onDoubleTap");
        return true;
    }


}
